$(function () {
    var form = layui.form
    var layer = layui.layer
    form.verify({
        nickname: function (value) {
            if (value.length > 6) {
                return ('长度必须1-6位')
            }
        }
    })
    get1()
    function get1() {
        $.ajax({
            method: "GET",
            url: "/my/userinfo",
            success: function (res) {
                if (res.code !== 0) {
                    return layer.msg("获取用户信息失败")
                }
                console.log(res);
                // 调用form里面的val方法为form填充值
                form.val('formUserInfo', res.data)
            }
        })
    }
    $('#btnReset').on('click', function (e) {
        e.preventDefault()
        get1()
    })
    $('.layui-form').on('submit', function (e) {
        e.preventDefault()

        $.ajax({
            method: "PUT",
            url: "/my/userinfo",
            data: $(this).serialize(),
            success: function (res) {
                if (res.code !== 0) {
                    return layer.msg('更新用户信息失败')
                }
                layer.msg('更新用户信息成功')
                window.parent.get()
            }
        })
    })
})